package com.tourism.exception;

import com.tourism.util.common.Response;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description
 * @Author z
 * @Date 2021-04-27 20:24
 */
@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Response exceptionHandler(Exception e) {
        System.out.println("未知异常！原因是:" + e);
        return Response.error(e.getMessage());
    }

    @ExceptionHandler(value = GlobalException.class)
    @ResponseBody
    public Response globalExceptionHandler(GlobalException e) {
        return Response.error(e.getExceptionEnum().getCode(), e.getMessage());
    }
}
